﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using seiacpscs.sortalgorithms;

namespace TestProject1.sortalgorithms
{
    /// <summary>
    /// Summary description for SelectionSortTestCase
    /// </summary>
    [TestClass]
    public class SelectionSortTestCase
    {
        public SortAlgorithm Algorithm { get; set; }


        public SelectionSortTestCase()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        [TestInitialize()]
        public void setup()
        {
            Algorithm = SortAlgorithmFactory.SelectionSort;
        }


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestSortWithEmptyArray()
        {

            int[] items = { };

            Algorithm.Sort(items);

            Assert.AreEqual(items.Length, 0);

        }

        [TestMethod]
        public void testSortwithOneItem()
        {

            int[] items = { 5 };

            Algorithm.Sort(items);

            Assert.AreEqual(items[0], 5);
        }

        [TestMethod]
        public void testSortwithTwoItems()
        {

            int[] items = { 5, 1 };

            Algorithm.Sort(items);
            Assert.AreEqual(items[0], 1);
            Assert.AreEqual(items[1], 5);
        }

        [TestMethod]
        public void testSort()
        {

            int[] items = { 5, 1, 4, 2, 8 };

            Algorithm.Sort(items);

            Assert.AreEqual(items[0], 1);
            Assert.AreEqual(items[1], 2);
            Assert.AreEqual(items[2], 4);
            Assert.AreEqual(items[3], 5);
            Assert.AreEqual(items[4], 8);
        }

    }
}
